/*
 * @Author: llixxm
 * @Date: 2020-04-27 17:08:36
 * @Description: 业务单元/利润中心 参照
 */
import { getBusinessInfo } from 'nc-lightapp-front';
import ReferLoader from '../../ReferLoader/index.js';
import {accbookRefcode, liabilityCenterOrgRefCode, businessUnitVersionRefCode} from '../../ReferLoader/constants.js';

//params:{referType:"", isQueryByVersion: false}
//GL123利润中心参照:liabilityCenter, isShowUnit业务单元参照:buSecond
let buSecondRefer = (page, params) => {
    let buziInfo = getBusinessInfo();
    let {referType, pk_accountingbook, disabled, isQueryByVersion, onChangeCallBack} = params;
    let {GL123,financeorg} = page.state
    let refcode = GL123 ? liabilityCenterOrgRefCode : businessUnitVersionRefCode; //
    // let value = GL123 ? liabilityCenter : buSecond;
    let value = page.state[referType];
    let defaultQueryCondition = {
        "TreeRefActionExt": 'nccloud.web.gl.ref.GLBUVersionWithBookRefSqlBuilder',
        "isDataPowerEnable": 'Y',
        "DataPowerOperationCode" : 'fi',
        "pk_accountingbook": pk_accountingbook,
        // "VersionStartDate": buziInfo.businessDate.split(' ')[0]
    }
    
    if(isQueryByVersion){
        defaultQueryCondition.VersionStartDate = buziInfo.businessDate.split(' ')[0]; //有的节点不需要通过VersionStartDate过滤
    }
    let libCenQueryCondition = {
        "isDataPowerEnable": 'Y',
        "DataPowerOperationCode" : 'fi',
        'financeorg':financeorg,
        'vdata': buziInfo.businessDate.split(' ')[0]
    }
    return(
        <ReferLoader
            tag = {referType}
            fieldid = {referType}
            refcode = {refcode}
            value = {value}
            isMultiSelectedEnabled={true}
            isShowDisabledData = {true}
            isHasDisabledData = {true}
            disabled = {disabled}
            queryCondition = {() =>{
                let queryCondition = GL123 ? libCenQueryCondition : defaultQueryCondition;
                return queryCondition;
            }}
            onChange={(v)=>{
                onChangeCallBack && onChangeCallBack();
                page.setState({
                    [referType]: v,
                }, () => {
                    if(pk_accountingbook) {
                    }
                })
            }}
        />
    )
}
export default buSecondRefer;